//
//  PreviewViewController.m
//  Runone
//
//  Created by runone01 on 16/7/27.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "PreviewViewController.h"
#import <MAMapKit/MAMapKit.h>
#import <AMapFoundationKit/AMapFoundationKit.h>
#import "Define.h"
#import "BCNetAPIClient.h"
#import "MJExtension.h"
#import "CurrentEvent.h"
#import "DevicesViewController.h"
#import "RequestGinsengModel.h"
#import "RequestHelper.h"
#import "AppLocalManager.h"
#import "AppDelegate.h"
#import "MineViewController.h"
#import "SVProgressHUD.h"
#import "TableOperation.h"
#import "PileInfo.h"
#import "ROPointAnnotation.h"
#import "CustomAnnotationView.h"
#import "AppDelegate.h"
#import "CommonUtilityjudge.h"
#import "DeviceBaseInfo.h"
#import "HighWayRoadRecord.h"
//#import "CoordinateConvertTool.h"
#import "OneConst.h"
#import "CarManagerView.h"
#import "StationModel.h"
#import "HighwayMergeRoadRecordModel.h"
#import "HighWayRoadRecordDirectionInfoModel.h"
#import "HighwayMergeInfoModel.h"
#import "MergeJsonModel.h"
#import "LineMergeJsonModel.h"
#import "TableOperation.h"
#import "Define.h"
#import "CurrentContructDetailViewController.h"
#import "CurrentIncidentDetailViewController.h"
#import "EventManagementViewController.h"
#import "UIViewController+Loading.h"
#import "BDMTollEventTypeDefineInfoModel.h"
#import "UIView+Addition.h"

#define kScreenH    [UIScreen mainScreen].bounds.size.height
@interface PreviewViewController ()<MAMapViewDelegate,UITabBarControllerDelegate>

@property (nonatomic, strong) MAMapView *mapView;//地图
@property (weak, nonatomic) IBOutlet UIView *listView;//列表视图
@property (weak, nonatomic) IBOutlet UIButton *deviceBtn;//设备按钮
@property (weak, nonatomic) IBOutlet UIButton *roadBtn;//路况按钮
@property (weak, nonatomic) IBOutlet UIButton *mineBtn;//我的按钮
@property (weak, nonatomic) IBOutlet UIButton *currentEventBtn;//当前事件按钮
@property (weak, nonatomic) IBOutlet UIButton *enlargeBtn;
@property (weak, nonatomic) IBOutlet UIButton *narrowBtn;
@property (weak, nonatomic) IBOutlet UIView *containView;
@property (nonatomic)       float la,lo;

@property (nonatomic, strong) NSMutableArray *allAnnotations;
@property (nonatomic, strong) NSMutableArray *eveCurData;//当前事件的数组
@property (nonatomic, strong) NSArray *dataArray;
@property (nonatomic, strong) CarManagerView *preView;//底部滑出视图
// ****************************** -数据模型- ******************************
@property (nonatomic, strong) HighwayMergeRoadRecordModel *mainModel;
@property (nonatomic, strong) HighwayMergeRoadRecordModel *southModel;
@property (nonatomic, strong) HighwayMergeRoadRecordModel *northModel;
@property (nonatomic, strong) CustomAnnotationView *selectedAnnoView;

@end

@implementation PreviewViewController

#pragma    ------------高速全览主界面



#pragma mark - lazyload
- (CarManagerView *)preView {
    if (!_preView) {
        CarManagerView *preView = [[CarManagerView alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height, self.view.frame.size.width, BottomSliderViewH)];
        _preView = preView;
        [self.view addSubview:_preView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(preManagerDetail)];
        [_preView addGestureRecognizer:tap];
    }
    return _preView;
}

- (NSMutableArray *)allAnnotations {
    if (!_allAnnotations) {
        NSMutableArray *allAnnotations = [[NSMutableArray alloc] init];
        _allAnnotations = allAnnotations;
    }
    return  _allAnnotations;
}

- (NSMutableArray *)eveCurData {
    if (!_eveCurData) {
        NSMutableArray *eveCurData = [[NSMutableArray alloc] init];
        _eveCurData = eveCurData;
    }
    return _eveCurData;
}

#pragma mark -life cycle

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UILabel *label                = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 30)];
    label.text                    = @"高速全览";
    label.textAlignment           = NSTextAlignmentCenter;
    label.textColor               = [UIColor whiteColor];
    self.navigationItem.titleView = label;
    self.view.autoresizingMask = NO;
    
    [self requestData];
    [self loadMapView];
    [self defaultAnnimation];
    self.tabBarController.delegate=self;
    _la = 0.8;
    _lo = 0.9;
    // 监听通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tabBarButtonRepeatClick) name:ROTabBarButtonRepeatClickNotification object:nil];
}

//tabbar图标点击
- (void)tabBarButtonRepeatClick {
    [self defaultAnnimation];
    [self Refresh];
}

//刷新数据
-(void)Refresh {
    RequestHelper *requestHelper=[[RequestHelper alloc] init];
    RequestGinsengModel *getAllCurrentEventModel = [[RequestGinsengModel alloc] init];
    getAllCurrentEventModel.URL         = GetEventDataURL;
    getAllCurrentEventModel.DataValue   = @"";
    getAllCurrentEventModel.UpdatedTime = @"";
    getAllCurrentEventModel.SystemCode  = @"GuangleHighway";
    getAllCurrentEventModel.MethodName  = @"GetAllCurrentEvent";
    requestHelper.block =^(RequestOutginseng *requestOutginseng,id dataValueModel){
        _dataArray      = [CurrentEvent mj_objectArrayWithKeyValuesArray:requestOutginseng.DataValue];
        [self.currentEventBtn setTitle:[NSString stringWithFormat:@"当前事件：%lu",(unsigned long)_dataArray.count] forState:UIControlStateNormal];
        [self loadAnnotationView];
    };
    [requestHelper RequestGinsengModel:getAllCurrentEventModel andPushController:self];
}
//加载数据
- (void) requestData {
    [SVProgressHUD showWithStatus:@"正在加载中..."];
    [self requsetAllHighWay];
}

- (void) requsetBDMTollEventTypeDefineInfo {
    RequestHelper *requestHelper               = [[RequestHelper alloc] init];
    RequestGinsengModel *getNewAllHighWayModel = [[RequestGinsengModel alloc] init];
    getNewAllHighWayModel.URL                  = GetEventDataURL;
    getNewAllHighWayModel.DataValue            = @"";
    getNewAllHighWayModel.UpdatedTime          = @"2000-01-01 01:00:00";
    getNewAllHighWayModel.SystemCode           = @"GuangleHighway";
    getNewAllHighWayModel.MethodName           = @"GetAllTollEventType";
    requestHelper.block=^(RequestOutginseng *requestOutginseng,id dataValueModel){
        if ([requestOutginseng.Code isEqualToString:@"001"]) {
            [self drawAllPile];
            [self drawPileNO];
            [self loadAnnotationView];
            [self.currentEventBtn setTitle:[NSString stringWithFormat:@"当前事件：%lu",(unsigned long)_dataArray.count] forState:UIControlStateNormal];
//            [SVProgressHUD showSuccessWithStatus:@"加载完毕"];
            [SVProgressHUD dismiss];
        }else {
            [SVProgressHUD showErrorWithStatus:@"网络请求失败,请稍后再试"];
        }
    };
    [requestHelper RequestGinsengModel:getNewAllHighWayModel andPushController:self];
}

//获取所有道路信息
- (void) requsetAllHighWay {
    RequestHelper *requestHelper               = [[RequestHelper alloc] init];
    RequestGinsengModel *getNewAllHighWayModel = [[RequestGinsengModel alloc] init];
    getNewAllHighWayModel.URL                  = GetDeviceDataURL;
    getNewAllHighWayModel.DataValue            = @"";
    getNewAllHighWayModel.UpdatedTime          = @"2000-01-01 01:00:00";
    getNewAllHighWayModel.SystemCode           = @"GuangleHighway";
    getNewAllHighWayModel.MethodName           = @"GetNewAllHighWayRoadInfo";
    requestHelper.block=^(RequestOutginseng *requestOutginseng,id dataValueModel){
        [self requestAllStation];
    };
    [requestHelper RequestGinsengModel:getNewAllHighWayModel andPushController:self];
}

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden=YES;
    self.tabBarController.tabBar.hidden=NO;
    
    [self.view addSubview:self.currentEventBtn];
    [self.view addSubview:self.listView];
    [self.view addSubview:self.containView];
    
    self.currentEventBtn.backgroundColor    = [UIColor whiteColor];
    self.currentEventBtn.layer.cornerRadius = 5;
    
    self.navigationController.navigationBar.hidden = YES;
    self.tabBarController.tabBar.hidden            = NO;
}

-(void)preManagerDetail {
    if ([_preView.currentModel.IncidentParentType integerValue] == 3) {
        CurrentContructDetailViewController *vc    = [[CurrentContructDetailViewController alloc] init];
        vc.CEModel                                 = _preView.currentModel;
        [self.navigationController pushViewController:vc animated:YES];
    } else {
        CurrentIncidentDetailViewController *vc    = [[CurrentIncidentDetailViewController alloc] init];
        vc.CEModel                                 = _preView.currentModel;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = YES;
    
    [UIView animateWithDuration:0.35 animations:^{
        self.enlargeBtn.transform      = CGAffineTransformIdentity;
        self.narrowBtn.transform       = CGAffineTransformIdentity;;
        self.currentEventBtn.transform = CGAffineTransformIdentity;
        _preView.transform             = CGAffineTransformIdentity;
    }];
}

//加载地图
-(void)loadMapView {
    [AMapServices sharedServices].apiKey = GETGAODEPAIKEY;
    _mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))];
    _mapView.delegate     = self;
    _mapView.showsCompass = NO;
    _mapView.showsScale   = YES ;
    _mapView.scaleOrigin  = CGPointMake(10, CGRectGetHeight(self.view.bounds) - 70);
    [self.view addSubview:_mapView];
}

#pragma mark - 地图代理方法
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id <MAAnnotation>)annotation {
    
    //    HighwayMergeRoadRecordModel *southRoadModel = mydelegate.HighWayRoadArray[2];
    if ([annotation isKindOfClass:[MAPointAnnotation class]]) {
        static NSString *pointReuseIndentifier = @"pointReuseIndentifier";
        CustomAnnotationView *annotationView = (CustomAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndentifier];
        if (annotationView == nil) {
            annotationView = [[CustomAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndentifier];
        }
//        if (!annotationView.CEModel ) {
//            annotationView.calloutView.hidden = YES;
//        }
//        annotationView.selected  = NO;
         annotationView.canShowCallout= NO;
        ROPointAnnotation *anno  = (ROPointAnnotation *)annotation;
        annotationView.pileModel = anno.pileModel;
        annotationView.CEModel   = anno.currentEventModel;
        //加载桩号的图标
        AppDelegate *mydelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
        HighwayMergeRoadRecordModel *mainRoadModel  = mydelegate.HighWayRoadArray[0];
                if ([anno.pileModel.RoadUID isEqualToString:mainRoadModel.RoadUID]) { // 6
                    if ([anno.pileModel.PileNo isEqualToString:@"K0"] ) {
                        annotationView.image = [UIImage imageNamed:@"gaosuquanlan_K0"];
                    }
                    if ([anno.pileModel.PileNo isEqualToString:@"K53"]) {
                        annotationView.image = [UIImage imageNamed:@"gaosuquanlan_K53"];
                    }
                    if ([anno.pileModel.PileNo isEqualToString:@"K84"]) {
                        annotationView.image = [UIImage imageNamed:@"gaosuquanlan_K84"];
                    }
                    if ([anno.pileModel.PileNo isEqualToString:@"K129"]) {
                        annotationView.image = [UIImage imageNamed:@"gaosuquanlan_K129"];
                    }
                    if ([anno.pileModel.PileNo isEqualToString:@"K189"]){
                        annotationView.image = [UIImage imageNamed:@"gaosuquanlan_K189"];
                    }
                    if ([anno.pileModel.PileNo isEqualToString:@"K222"]) {
                        annotationView.image = [UIImage imageNamed:@"gaosuquanlan_K222"];
                    }
                    if ([anno.pileModel.PileNo isEqualToString:@"K269"]){
                        annotationView.image = [UIImage imageNamed:@"K269@2x.png"];
                    }
                }
        if (anno.currentEventModel) { //加载事件类型的图标
            
            if ([anno.currentEventModel.IncidentParentType isEqualToString:@"3"]) {
                if (anno.currentEventModel.IsRamp) {
                    annotationView.image = [UIImage imageNamed:@"ramp_construction"];
                }else {
                annotationView.image  = [UIImage imageNamed:@"main_line_construction"];
                }
                
            } else {
                annotationView.image  = [UIImage imageNamed:@"accident_icon"];
            }
        }
        
        annotationView.centerOffset = CGPointMake(0, -annotationView.image.size.height / 2);
        return annotationView;
    }
    return nil;
}

- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id<MAOverlay>)overlay {
    if ([overlay isKindOfClass:[MAPolyline class]]) {
        MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:overlay];
        polylineRenderer.fillColor   = [UIColor colorWithRed:54.0/255 green:105.0/255 blue:145.0/255 alpha:0.3];
        polylineRenderer.lineWidth   = 10.f;
        polylineRenderer.lineDash    = NO;
        return polylineRenderer;
    }
    return nil;
}
#pragma mark - 绘制桩号
- (void) drawPileNO {  // 特定的7个桩号
    AppDelegate *myDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
    NSArray *pileArray = myDelegate.PirArray;
    for (PileInfo *model in pileArray) { // 筛选
        if ([model.PileNo isEqualToString:@"K0"] || [model.PileNo isEqualToString:@"K53"] || [model.PileNo isEqualToString:@"K84"] || [model.PileNo isEqualToString:@"K129"] || [model.PileNo isEqualToString:@"K189"]|| [model.PileNo isEqualToString:@"K222"] || [model.PileNo isEqualToString:@"K269"]) {
            double latitude  = model.Latitude ;  //  _Latitude	double	25.341705322265625
            double longitude = model.Longitude ; //  _Longitude	double	112.95156860351563
            ROPointAnnotation *roAnnotation = [[ROPointAnnotation alloc] init];
            CLLocationCoordinate2D ret  = CLLocationCoordinate2DMake(latitude, longitude);
            roAnnotation.coordinate     = ret;
            roAnnotation.pileModel      = model;
            [self.allAnnotations addObject:roAnnotation];
        }
    }
    [_mapView addAnnotations:self.allAnnotations];
}
//在地图上绘制路线
- (void)drawAllPile {
    AppDelegate *mydelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    NSArray *allPileArray = mydelegate.PirArray;
    for (HighwayMergeRoadRecordModel *roadModel in mydelegate.HighWayRoadArray) {
        NSMutableArray *drawArray = [[NSMutableArray alloc] init];
        for (PileInfo *model in allPileArray) {
            if ([model.RoadUID isEqualToString:roadModel.RoadUID]) {     // 主干道
                [drawArray addObject:model];}
        }
        MAMapPoint drawPoly[drawArray.count];
        for (int i = 0;  i < drawArray.count; i++) {
            PileInfo *model = drawArray[i];
            drawPoly[i] = MAMapPointForCoordinate(CLLocationCoordinate2DMake(model.Latitude, model.Longitude));
        }
        MAPolyline *polyLine = [MAPolyline polylineWithPoints:drawPoly count:drawArray.count];
        [_mapView addOverlay:polyLine];
    }
}

//获取所有事件
-(void)requestCurrentEvent {
    //获取当前事件
    RequestHelper *requestHelper=[[RequestHelper alloc] init];
    RequestGinsengModel *getAllCurrentEventModel = [[RequestGinsengModel alloc] init];
    getAllCurrentEventModel.URL         = GetEventDataURL;
    getAllCurrentEventModel.DataValue   = @"";
    getAllCurrentEventModel.UpdatedTime = @"";
    getAllCurrentEventModel.SystemCode  = @"GuangleHighway";
    getAllCurrentEventModel.MethodName  = @"GetAllCurrentEvent";
    requestHelper.block =^(RequestOutginseng *requestOutginseng,id dataValueModel){
        _dataArray      = [CurrentEvent mj_objectArrayWithKeyValuesArray:requestOutginseng.DataValue];
         [self requsetBDMTollEventTypeDefineInfo];
    };
    [requestHelper RequestGinsengModel:getAllCurrentEventModel andPushController:self];
}

//获取所有收费站信息表
- (void) requestAllStation {
    RequestHelper *requestHelper=[[RequestHelper alloc] init];
    RequestGinsengModel *getAllCurrentEventModel = [[RequestGinsengModel alloc] init];
    getAllCurrentEventModel.URL         = GetDeviceDataURL;
    getAllCurrentEventModel.DataValue   = @"";
    getAllCurrentEventModel.UpdatedTime = @"";
    getAllCurrentEventModel.SystemCode  = @"GuangleHighway";
    getAllCurrentEventModel.MethodName  = @"GetAllTollStationInfo";
    requestHelper.block =^(RequestOutginseng *requestOutginseng,id dataValueModel){
        [self requestAllDevices];
    };
    [requestHelper RequestGinsengModel:getAllCurrentEventModel andPushController:self];
}
//获取桩号信息
- (void) requestPileNO {
    //获取桩号信息
    RequestHelper *requestHelper=[[RequestHelper alloc] init];
    RequestGinsengModel *getAllPirlInfoModel = [[RequestGinsengModel alloc] init];
    getAllPirlInfoModel.URL                  = GetDeviceDataURL;
    getAllPirlInfoModel.DataValue            = @"";
    getAllPirlInfoModel.UpdatedTime          = @"2012-01-12 12:00:00";
    getAllPirlInfoModel.SystemCode           = @"GuangleHighway";
    getAllPirlInfoModel.MethodName           = @"GetAllPileInfo";
    requestHelper.block=^(RequestOutginseng *requestOutginseng,id dataValueModel){
        [self requestCurrentEvent];
    };
    [requestHelper RequestGinsengModel:getAllPirlInfoModel andPushController:self];
}

- (void) requestAllDevices {
    RequestHelper *requestHelper=[[RequestHelper alloc] init];
    RequestGinsengModel *getAllDeviceBaseModel=[[RequestGinsengModel alloc] init];
    getAllDeviceBaseModel.URL        = GetDeviceDataURL;
    getAllDeviceBaseModel.DataValue=@"";
    getAllDeviceBaseModel.UpdatedTime= @"2012-01-12 12:00:00";
    getAllDeviceBaseModel.SystemCode=@"GuangleHighway";
    getAllDeviceBaseModel.MethodName=@"GetAllDeviceBaseInfo";
    requestHelper.block=^(RequestOutginseng *requestOutginseng,id dataValueModel){
        if ([requestOutginseng.Code isEqualToString:@"001"]) {
            [self requestPileNO];
        }
    };
    [requestHelper RequestGinsengModel:getAllDeviceBaseModel andPushController:self];
}
//设备列表
- (IBAction)deviceEvent:(UIButton *)sender {
    DevicesViewController *deviceVC=[[DevicesViewController alloc] init];
    [self.navigationController pushViewController:deviceVC animated:YES];
}

-(void)loadAnnotationView {
    AppDelegate *myDelegate        = (AppDelegate*) [UIApplication sharedApplication].delegate;
    NSArray *pileArray             =  myDelegate.PirArray;
    
    NSMutableArray *temp           = [[NSMutableArray alloc] init];
    for (int i=0 ;i<_dataArray.count; i++) {
        CurrentEvent *CEModel      = _dataArray[i];
        NSString *pileStr          = CEModel.BeginPile;

                if ([CEModel.Latitude integerValue] != 0 && [CEModel.Longitude integerValue] != 0 ) {//如果有经纬度
        
                    [temp addObject:CEModel];
                }else {
                    for (PileInfo *pileModel in pileArray) {
                        if ([pileStr isEqualToString: pileModel.PileNo] && [pileModel.RoadUID isEqualToString:CEModel.RoadUID]) {
                            CEModel.Latitude   = [NSString stringWithFormat:@"%f",pileModel.Latitude];
                            CEModel.Longitude  = [NSString stringWithFormat:@"%f", pileModel.Longitude];
                            [temp addObject:CEModel];
                        }
    }
        }
    }
    for (CurrentEvent *CEModel in temp) {
        ROPointAnnotation *roAnnotation = [[ROPointAnnotation alloc] init];
        float latitude                  = [CEModel.Latitude floatValue];
        float longitude                 = [CEModel.Longitude floatValue];
        CLLocationCoordinate2D ret      = CLLocationCoordinate2DMake(latitude, longitude);
        roAnnotation.coordinate         = ret;
        roAnnotation.currentEventModel  = CEModel;
        [self.eveCurData addObject:roAnnotation];
    }
    [_mapView addAnnotations:self.eveCurData];
}
//实时路况
- (IBAction)roadEvent:(UIButton *)sender {
    
    sender.selected=!sender.selected;
    if (sender.selected) {
        _mapView.showTraffic=YES;
    } else {
        _mapView.showTraffic=NO;
    }
}
//当前事件
- (IBAction)currentEvent:(UIButton *)sender {
    self.tabBarController.selectedIndex = 3;
    [[NSNotificationCenter defaultCenter] postNotificationName:@"currenBtnClick" object:nil];
}

//屏幕试配
-(void)defaultAnnimation { // 2.189339--1.353861--8.815084--24.343250--113.323592
    if (iPhone6plus) {
        MACoordinateSpan  span                  = MACoordinateSpanMake(2.294286, 1.441601);
        CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(24.343247, 113.323544);
        MACoordinateRegion region = MACoordinateRegionMake(centerCoordinate, span);
        _mapView.region           = region;
        [_mapView setCenterCoordinate:centerCoordinate animated:NO];
        _mapView.zoomLevel = 9.098923;
    }
    if (iPhone6) {
        MACoordinateSpan span = MACoordinateSpanMake(2.246064, 1.386080);
        CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(24.343247, 113.323544);
        MACoordinateRegion region = MACoordinateRegionMake(centerCoordinate, span);
        _mapView.region = region;
        [_mapView setCenterCoordinate:centerCoordinate animated:NO];
        _mapView.zoomLevel = 8.964810;
    }
    if (iPhone5) {
        MACoordinateSpan span = MACoordinateSpanMake(2.028609, 1.255746);
        CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(24.343247, 113.323544);
        MACoordinateRegion region = MACoordinateRegionMake(centerCoordinate, span);
        _mapView.region = region;
        [_mapView setCenterCoordinate:centerCoordinate animated:NO];
        _mapView.zoomLevel = 8.815084;
    }
}

//刷新按钮
- (IBAction)RefreshBtn:(UIButton *)sender {
    [self requestCurrentEvent];
}

- (IBAction)mineBtnClick:(id)sender {
    MineViewController *mineVC = [[MineViewController alloc] init];
    [self.navigationController pushViewController:mineVC animated:YES];
}
#pragma  mark - 地图放大与缩小
- (IBAction)enlargeBtnClick{
    _la-=0.1;
    _lo-=0.1;
    MACoordinateSpan span = MACoordinateSpanMake(_la,_lo);
    CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(24.140485, 113.252132);
    MACoordinateRegion region = MACoordinateRegionMake(centerCoordinate, span);
    [_mapView setCenterCoordinate:centerCoordinate];
    _mapView.region = region;
}
//缩放地图
- (IBAction)narrowBtnClick:(id)sender {
    _la+=0.3;
    _lo+=0.3;
    MACoordinateSpan span = MACoordinateSpanMake(_la, _lo);
    CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(24.140485, 113.252132);
    MACoordinateRegion region = MACoordinateRegionMake(centerCoordinate, span);
    [_mapView setCenterCoordinate:centerCoordinate];
    _mapView.region = region;
}
#pragma mark -annotationView
- (void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view {
    
    CustomAnnotationView *customView         = (CustomAnnotationView *)view;
    
    _selectedAnnoView = customView;
    //customView.calloutView.hidden = YES;
    if (!customView.CEModel ) { //过滤掉桩号
        customView.calloutView.hidden = YES;
        return;
    }
    self.preView.currentModel = customView.CEModel;
    [_preView setCurrentType:[_preView.currentModel.IncidentParentType integerValue] BeginPile:_preView.currentModel.BeginPile BeginPileDistance:_preView.currentModel.BeginPileDistance EndPile:_preView.currentModel.EndPile EndPileDistance:_preView.currentModel.EndPileDistance RoadUID:_preView.currentModel.RoadUID];
    if (customView.isSelected) {
        [UIView animateWithDuration:0.35 animations:^{
            self.enlargeBtn.transform      = CGAffineTransformMakeTranslation(0, -BottomSliderViewH);
            self.narrowBtn.transform       = CGAffineTransformMakeTranslation(0, -BottomSliderViewH);
            self.currentEventBtn.transform = CGAffineTransformMakeTranslation(0, -BottomSliderViewH);
            _preView.transform             = CGAffineTransformMakeTranslation(0, BottomSliderDistance);
        }];
    }
    customView.selected = NO;
    
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [UIView animateWithDuration:0.35 animations:^{
        self.enlargeBtn.transform      = CGAffineTransformIdentity;
        self.narrowBtn.transform       = CGAffineTransformIdentity;
        self.currentEventBtn.transform = CGAffineTransformIdentity;
        _preView.transform             = CGAffineTransformIdentity;
    }];
}
//移除通知
- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
